package cn.hughie.geo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yuh
 * @date 2018/5/25 15:34
 * @description
 */
public class PointUtil {

    private PointUtil() {
    }


    public static String getCacheKey(String prefix, List<Point> points) {
        StringBuilder sb = new StringBuilder(prefix);
        for (Point point : points) {
            String longtitude = point.getLongtitude();
            String latitude = point.getLatitude();
            int lngPotIndex = longtitude.indexOf(".");
            int latPotIndex = latitude.indexOf(".");
            if (longtitude.length() - lngPotIndex < 6 || latitude.length() - latPotIndex < 6) {
                sb.delete(0, sb.length());
                return sb.toString();
            }
            sb.append(longtitude.substring(0, lngPotIndex + 6))
                    .append(",")
                    .append(latitude.substring(0, latPotIndex + 6))
                    .append(";");
        }
        sb.delete(sb.length() - 1, sb.length());
        return sb.toString();
    }

    public static void main(String[] args) {
        Point point = Point.valueOf("123.12336", "12.123456");
        Point point1 = Point.valueOf("123.12336", "12.123456");
        List<Point> points = new ArrayList<>();
        points.add(point);
        points.add(point1);
        System.out.println(getCacheKey("BAIDU:", points));
    }

}
